'''
Created on 2011-10-26

@author: Administrator
'''
import os
import datetime
import Queue
#from packStockData.stockdata import StockWeek
stockdata_rootpath='f:\\stock2011datacenter'
rawcontentpath=os.path.join(stockdata_rootpath,'rawcontent')
errordatapath=os.path.join(stockdata_rootpath,'errorlog')
jobtodopath=os.path.join(stockdata_rootpath,'jobtodo')
stockbydatepath=os.path.join(stockdata_rootpath,'bydate')
stockbycodepath=os.path.join(stockdata_rootpath,'bycode')
stockfirstdate='2000/1/1'
defaultfirstdate=20000101
urlqueue=Queue.Queue()
g_jobsnumber=0
workers_number=150
threadtimeout=5
reglist=['CH','HK','US']  

def str2date(sdate):
    return sdate
    return datetime.date(int(sdate[:4]),int(sdate[4:6]),int(sdate[6:8]))
def date2int(sdate):
    return sdate.year*10000+sdate.month*100+sdate.day
def int2date(s):
    sdate=str(s)
    if sdate.find('/')<0 and sdate.find('-')<0 :
        return datetime.date(int(sdate[:4]),int(sdate[4:6]),int(sdate[6:8]))
    sdate=sdate.replace('/','-')
    s=[]
    s=sdate.split('-')
    return datetime.date(int(s[0]),int(s[1]),int(s[2]))
def myfloat(src):
    if len(src)==0:return 0.0
    else: return float(src)
    
#############################################################
def sameweek(src,dst):
    if abs((dst-src).days)>=7:return False
    
def createweeklist():
    startday=int2date(defaultfirstdate)
    endday=int2date(20500101)
    print startday,endday,(startday-endday).days,startday.weekday()
    daylist=[]
    weeklist={}
    weeknum=1
    while endday>startday:
        
        if endday.weekday()<5:
            if endday.weekday()==0:weeknum=weeknum+1
            weeklist[date2int(endday)]=weeknum
                  
        endday=endday-datetime.timedelta(days=1)
    return weeklist
    
    
if __name__ == '__main__':
    createweeklist()
#    curdate=datetime.date.today()
#    firstdate=int2date(defaultfirstdate)
#    print curdate,firstdate
#    
#    weeklist=[]
#    t=curdate
#    thisweek=[]
#    while curdate>firstdate:
#        t=curdate-datetime.timedelta(days=1)
        
        